package demo1;

public class Test821one {
    //斐波那契数列
    public static int way(int n){
        if(n==1|n==2)
            return 1;
        else
            return way(n-1)+way(n-2);
    }
    public static void way1(){
        int sum=0;
        for(int i=0;i<=2000;i++){
            sum=(i*i);
            if(sum<=2000){
                System.out.print(i+" ");
            }
        }
    }
    public static void way2(){
        for(int i=0;i*i<=2000;i++){
            System.out.print(i+" ");
        }
    }
    public static int  way3(int n){
        int a=n*n;
       if(a>2000){
           return -1;
       }else if(a<=2000){
           System.out.print(n+" ");
       }
       return way3(n+1);


    }
    public static void main(String[]args){
        int f1=1;
        int f2=1;
        int f3=0;
        int n=3;
        for(int i=0;i<n;i++){//前两项的相加次数
            f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        System.out.println("迭代的斐波那契数列结果为："+f3);
        int num=way(5);
        System.out.println("递归的斐波那契数列的结果为"+num);
        //求2000以内的完全平方数
        way1();//法1
        System.out.println("=======");
        way2();//法2
        System.out.println("=======");
        way3(0);//法2
        System.out.println("=====");

    }

}
